package com.example.administrator.androidui9;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    TextView tvCity;
    TextView tvTemp;
    Button btnBj, btnSH, btnGz;
    List<WeatherInfo> weatherInfos;
    int index = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initEvent();
        initData();
    }

    private void initData() {
        InputStream is = getResources().openRawResource(R.raw.weather1);
        try {
            weatherInfos = WeatherService.getInfosFromXML(is);
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        WeatherInfo weatherInfo = weatherInfos.get(index);
        tvCity.setText(weatherInfo.getName());
        tvTemp.setText(weatherInfo.getTemp());
    }



    private void initEvent() {
        btnGz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


    }

    private void initView() {
        tvCity = findViewById(R.id.tv_city);
        tvTemp = findViewById(R.id.tv_temp);
        btnBj =findViewById(R.id.btn_bj);
        btnGz =findViewById(R.id.btn_gz);
        btnSH =findViewById(R.id.btn_sh);

    }
}
